package com.ggh.jinjilive.ui.mine;

import androidx.lifecycle.MutableLiveData;

import com.ggh.jinjilive.mobile.ResultEntity;
import com.ggh.jinjilive.mobile.live.SellGoodsMobile;
import com.ggh.jinjilive.remotedata.InterceptObserver;
import com.ggh.jinjilive.remotedata.systemapi.SystemApiService;
import com.ggh.jinjilive.ui.BaseViewModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class TaskReceiveViewModel extends BaseViewModel {
    //我的任务
    public MutableLiveData<List<SellGoodsMobile>> mSellGoodsMobileList = new MutableLiveData<>();


    public TaskReceiveViewModel(SystemApiService apiCallInterface) {
        super(apiCallInterface);
    }
    /**
     * 我的任务
     */
    public void myTaskList(int status){
        if (isRefresh) {
            page = 1;
        }else {
            page = page + 1;
        }
        Map<String, Object> paramsa = new HashMap<>();
        paramsa.put("status",status);
        paramsa.put("page",page);
        addSubscribe(apiCallInterface.myTaskList(paramsa).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<SellGoodsMobile>>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                List<SellGoodsMobile> sellGoodsMobileList = (List<SellGoodsMobile>) resultEntity.getData();
                mSellGoodsMobileList.setValue(sellGoodsMobileList);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {

            }

        }));
    }

    /**
     * 商家任务
     */
    public void TaskTaskList(){
        if (isRefresh) {
            page = 1;
        }else {
            page = page + 1;
        }
        Map<String, Object> paramsa = new HashMap<>();
        paramsa.put("status",1);
        paramsa.put("page",page);
        addSubscribe(apiCallInterface.TaskTaskList(paramsa).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<SellGoodsMobile>>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                List<SellGoodsMobile> sellGoodsMobileList = (List<SellGoodsMobile>) resultEntity.getData();
                mSellGoodsMobileList.setValue(sellGoodsMobileList);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {

            }

        }));
    }

}
